package com.ymatou.iapi.productprice.testcase;

import java.util.Date;

import org.json.JSONObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.productprice.parameter.PriceConfig;
import com.ymatou.iapi.productprice.parameter.ProductAllPriceBean;
import com.ymatou.iapi.productprice.parameter.ProductPriceBean;
import com.ymatou.iapi.productprice.service.GetPriceByProdIdTradeIsolationCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.AdminCallService;
import com.ymttest.business.service.ProductPriceCallService;
import com.ymttest.database.mongo.jproduct.ActivityProductsWapper;
import com.ymttest.database.mongo.jproduct.ProductTimeStampWapper;
import com.ymttest.database.mongo.jproduct.ProductsWapper;
import com.ymttest.utils.MapUtil;
import com.ymttest.utils.YMTDateUtil;

public class Ts_GetPriceByProdIdTradeIsolation {
	private static int newBuyerId = ProductPriceCallService.getNewCustomer();
	private static int oldBuyerId = ProductPriceCallService.getOldCustomer();
	private static GetPriceByProdIdTradeIsolationCall  getPriceByProdIdTradeIsolationCall = new GetPriceByProdIdTradeIsolationCall();
	private static ProductTimeStampWapper productTimeStampWapper = new ProductTimeStampWapper();
	private static ActivityProductsWapper activityProductsWapper = new ActivityProductsWapper();

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("交易隔离查询接口, 根据商品id查询商品价格");
	}

	@Before
	public void caseUp() {
		
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getPriceByProdIdTradeIsolationCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetPriceByProdIdTradeIsolation_001() {
		Logger.start(true, "非交易隔离,普通新人活动");
		try {

			ProductAllPriceBean productAllPriceBean = ProductPriceCallService.getProdPriceWithActivity_NewBuyerAndNoIsolation();
			String productId = productAllPriceBean.getProductId();
			
			
			//1 码头新客户 查询结果为活动价格
			ProductPriceBean newProductPrice = ProductPriceCallService.getProductPriceBeanByUserLevel(productAllPriceBean,true,false);
			JSONObject ret = getPriceByProdIdTradeIsolationCall.callAndGetReturnData(newBuyerId, productId);
			ProductPriceCallService.checkPriceItem(ret, newProductPrice);
			
			
			//2码头老客户查询结果为普通商品价格逻辑

			//vip
			ProductPriceCallService.updateSellerBuyerToVipOrNot(ProductPriceCallService.sellerId, oldBuyerId, true);
			ProductPriceBean oldProductPrice = ProductPriceCallService.getProductPriceBeanByUserLevelAndIgnoreActivityPrice(productAllPriceBean,false);
			JSONObject ret2 = getPriceByProdIdTradeIsolationCall.callAndGetReturnData(oldBuyerId, productId);
			ProductPriceCallService.checkPriceItem(ret2, oldProductPrice);
			
			//no vip
			ProductPriceCallService.updateSellerBuyerToVipOrNot(ProductPriceCallService.sellerId, oldBuyerId, false);
			ProductPriceBean oldProductPriceNoVip = ProductPriceCallService.getProductOrigPriceBeanByUserLevel(productAllPriceBean, true);
			ret2 = getPriceByProdIdTradeIsolationCall.callAndGetReturnData(oldBuyerId, productId);
			ProductPriceCallService.checkPriceItem(ret2, oldProductPriceNoVip);
			ProductPriceCallService.updateSellerBuyerToVipOrNot(ProductPriceCallService.sellerId, oldBuyerId, true);
			
			
			
			
			if (PriceConfig.isCacheCheck){
				Logger.debug("缓存检查");
				//===========================================================================================================
				//修改mongo数据库价格，由于时间戳没有变化，应该查询缓存中数据，所以结果没有变
				int inaid = Integer.parseInt(activityProductsWapper.getByProdId(productId).get("inaid").toString());
				ProductAllPriceBean productAllPriceBeanUpdate = ProductPriceCallService.updatePriceInMgo(productAllPriceBean,inaid);
				
				ret = getPriceByProdIdTradeIsolationCall.callAndGetReturnData(newBuyerId, productId);
				if (PriceConfig.isCacheActivityProduct){
					ProductPriceCallService.checkPriceItem(ret, newProductPrice);
				}else{
					ProductPriceBean newProductPriceUpdate = ProductPriceCallService.getProductPriceBeanByUserLevel(productAllPriceBeanUpdate,true,false);
					ProductPriceCallService.checkPriceItem(ret, newProductPriceUpdate);
				}
				
				ret2 = getPriceByProdIdTradeIsolationCall.callAndGetReturnData(oldBuyerId, productId);
				ProductPriceCallService.checkPriceItem(ret2, oldProductPrice);
				
				//修改时间戳，应该查询mongo库中数据，结果发生变化
				productTimeStampWapper.update(productId, MapUtil.hashMap("aut",new Date(),"cut",new Date())); 
				
				//新客修改后价格检查
				ProductPriceBean newProductPriceUpdate = ProductPriceCallService.getProductPriceBeanByUserLevel(productAllPriceBeanUpdate,true,false);
				ret = getPriceByProdIdTradeIsolationCall.callAndGetReturnData(newBuyerId, productId);
				ProductPriceCallService.checkPriceItem(ret, newProductPriceUpdate);
				
				//老客修改后价格检查
				ProductPriceBean oldProductPriceUpdate = ProductPriceCallService.getProductPriceBeanByUserLevelAndIgnoreActivityPrice(productAllPriceBeanUpdate,false);
				ret2 = getPriceByProdIdTradeIsolationCall.callAndGetReturnData(oldBuyerId, productId);
				ProductPriceCallService.checkPriceItem(ret2, oldProductPriceUpdate);
			}
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetPriceByProdIdTradeIsolation_002() {
		Logger.start(true, "非交易隔离,非新人活动");
		try {
			ProductAllPriceBean productAllPriceBean = ProductPriceCallService.getProdPriceWithActivity_NoNewBuyerAndNoIsolation();
			String productId = productAllPriceBean.getProductId();
		
			//1 码头新客户 查询结果为活动价格
			ProductPriceBean newProductPrice = ProductPriceCallService.getProductPriceBeanByUserLevel(productAllPriceBean,true,false);
			JSONObject ret = getPriceByProdIdTradeIsolationCall.callAndGetReturnData(newBuyerId, productId);
			ProductPriceCallService.checkPriceItem(ret, newProductPrice);
			
			
			//2码头老客户查询结果为活动价格
			ProductPriceBean oldProductPrice = ProductPriceCallService.getProductPriceBeanByUserLevel(productAllPriceBean,false,false);
			JSONObject ret2 = getPriceByProdIdTradeIsolationCall.callAndGetReturnData(oldBuyerId, productId);
			ProductPriceCallService.checkPriceItem(ret2, oldProductPrice);
			
			if (PriceConfig.isCacheCheck){
				Logger.debug("缓存检查");
				//===========================================================================================================
				//修改mongo数据库价格，由于时间戳没有变化，应该查询缓存中数据，所以结果没有变
				int inaid = Integer.parseInt(activityProductsWapper.getByProdId(productId).get("inaid").toString());
				ProductAllPriceBean productAllPriceBeanUpdate = ProductPriceCallService.updatePriceInMgo(productAllPriceBean,inaid);
				
				ret = getPriceByProdIdTradeIsolationCall.callAndGetReturnData(newBuyerId, productId);
				ret2 = getPriceByProdIdTradeIsolationCall.callAndGetReturnData(oldBuyerId, productId);
				if (PriceConfig.isCacheActivityProduct){
					ProductPriceCallService.checkPriceItem(ret, newProductPrice);
					ProductPriceCallService.checkPriceItem(ret2, oldProductPrice);
					
				}else{
					ProductPriceBean newProductPriceUpdate = ProductPriceCallService.getProductPriceBeanByUserLevel(productAllPriceBeanUpdate,true,false);
					ProductPriceCallService.checkPriceItem(ret, newProductPriceUpdate);
					
					ProductPriceBean oldProductPriceUpdate = ProductPriceCallService.getProductPriceBeanByUserLevel(productAllPriceBeanUpdate,false,false);
					ProductPriceCallService.checkPriceItem(ret2, oldProductPriceUpdate);
				}
				
				
				//修改时间戳，应该查询mongo库中数据，结果发生变化
				productTimeStampWapper.update(productId, MapUtil.hashMap("aut",new Date(),"cut",new Date())); 
				
				//新客修改后价格检查
				ProductPriceBean newProductPriceUpdate = ProductPriceCallService.getProductPriceBeanByUserLevel(productAllPriceBeanUpdate,true,false);
				ret = getPriceByProdIdTradeIsolationCall.callAndGetReturnData(newBuyerId, productId);
				ProductPriceCallService.checkPriceItem(ret, newProductPriceUpdate);
				
				//老客修改后价格检查
				ProductPriceBean oldProductPriceUpdate = ProductPriceCallService.getProductPriceBeanByUserLevel(productAllPriceBeanUpdate,false,false);
				ret2 = getPriceByProdIdTradeIsolationCall.callAndGetReturnData(oldBuyerId, productId);
				ProductPriceCallService.checkPriceItem(ret2, oldProductPriceUpdate);
			}
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetPriceByProdIdTradeIsolation_003() {
		Logger.start(true, "交易隔离,新人活动");
		try {

			ProductAllPriceBean productAllPriceBean = ProductPriceCallService.getProdPriceWithActivity_NewBuyerAndIsolation();
			String productId = productAllPriceBean.getProductId();
		
			//1 码头新客户 查询结果为活动价格
			ProductPriceBean newProductPrice = ProductPriceCallService.getProductPriceBeanByUserLevel(productAllPriceBean,true,false);
			JSONObject ret = getPriceByProdIdTradeIsolationCall.callAndGetReturnData(newBuyerId, productId);
			ProductPriceCallService.checkPriceItem(ret, newProductPrice);
			
			
			//2码头老客户查询结果为普通商品价格
			//vip
			ProductPriceCallService.updateSellerBuyerToVipOrNot(ProductPriceCallService.sellerId, oldBuyerId, true);
			ProductPriceBean oldProductPrice = ProductPriceCallService.getProductPriceBeanByUserLevelAndIgnoreActivityPrice(productAllPriceBean,false);
			JSONObject ret2 = getPriceByProdIdTradeIsolationCall.callAndGetReturnData(oldBuyerId, productId);
			ProductPriceCallService.checkPriceItem(ret2, oldProductPrice);
			
			//no vip
			ProductPriceCallService.updateSellerBuyerToVipOrNot(ProductPriceCallService.sellerId, oldBuyerId, false);
			ProductPriceBean oldProductPriceNoVip = ProductPriceCallService.getProductOrigPriceBeanByUserLevel(productAllPriceBean, true);
			ret2 = getPriceByProdIdTradeIsolationCall.callAndGetReturnData(oldBuyerId, productId);
			ProductPriceCallService.checkPriceItem(ret2, oldProductPriceNoVip);
			ProductPriceCallService.updateSellerBuyerToVipOrNot(ProductPriceCallService.sellerId, oldBuyerId, true);
			
			if (PriceConfig.isCacheCheck){
				Logger.debug("缓存检查");
				//===========================================================================================================
				//修改mongo数据库价格，由于时间戳没有变化，应该查询缓存中数据，所以结果没有变
				int inaid = Integer.parseInt(activityProductsWapper.getByProdId(productId).get("inaid").toString());
				ProductAllPriceBean productAllPriceBeanUpdate = ProductPriceCallService.updatePriceInMgo(productAllPriceBean,inaid);
				
				ret = getPriceByProdIdTradeIsolationCall.callAndGetReturnData(newBuyerId, productId);
				if (PriceConfig.isCacheActivityProduct){
					ProductPriceCallService.checkPriceItem(ret, newProductPrice);
				}else{
					ProductPriceBean newProductPriceUpdate = ProductPriceCallService.getProductPriceBeanByUserLevel(productAllPriceBeanUpdate,true,false);
					ProductPriceCallService.checkPriceItem(ret, newProductPriceUpdate);
				}
				
				ret2 = getPriceByProdIdTradeIsolationCall.callAndGetReturnData(oldBuyerId, productId);
				ProductPriceCallService.checkPriceItem(ret2, oldProductPrice);
				
				//修改时间戳，应该查询mongo库中数据，结果发生变化
				productTimeStampWapper.update(productId, MapUtil.hashMap("aut",new Date(),"cut",new Date())); 
				
				//新客修改后价格检查
				ProductPriceBean newProductPriceUpdate = ProductPriceCallService.getProductPriceBeanByUserLevel(productAllPriceBeanUpdate,true,false);
				ret = getPriceByProdIdTradeIsolationCall.callAndGetReturnData(newBuyerId, productId);
				ProductPriceCallService.checkPriceItem(ret, newProductPriceUpdate);
				
				//老客修改后价格检查
				ProductPriceBean oldProductPriceUpdate = ProductPriceCallService.getProductPriceBeanByUserLevelAndIgnoreActivityPrice(productAllPriceBeanUpdate,false);
				ret2 = getPriceByProdIdTradeIsolationCall.callAndGetReturnData(oldBuyerId, productId);
				ProductPriceCallService.checkPriceItem(ret2, oldProductPriceUpdate);
			}
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetPriceByProdIdTradeIsolation_004() {
		Logger.start(true, "交易隔离,非新人活动");
		try {

			ProductAllPriceBean productAllPriceBean = ProductPriceCallService.getProdPriceWithActivity_NoNewBuyerAndIsolation();
			String productId = productAllPriceBean.getProductId();
		
			//1 码头新客户 查询结果为活动价格
			ProductPriceBean newProductPrice = ProductPriceCallService.getProductPriceBeanByUserLevel(productAllPriceBean,true,false);
			JSONObject ret = getPriceByProdIdTradeIsolationCall.callAndGetReturnData(newBuyerId, productId);
			ProductPriceCallService.checkPriceItem(ret, newProductPrice);
			
			
			//2码头老客户查询结果为活动价格
			ProductPriceBean oldProductPrice = ProductPriceCallService.getProductPriceBeanByUserLevel(productAllPriceBean,false,false);
			JSONObject ret2 = getPriceByProdIdTradeIsolationCall.callAndGetReturnData(oldBuyerId, productId);
			ProductPriceCallService.checkPriceItem(ret2, oldProductPrice);
			
			if (PriceConfig.isCacheCheck){
				Logger.debug("缓存检查");
				//===========================================================================================================
				//修改mongo数据库价格，由于时间戳没有变化，应该查询缓存中数据，所以结果没有变
				int inaid = Integer.parseInt(activityProductsWapper.getByProdId(productId).get("inaid").toString());
				ProductAllPriceBean productAllPriceBeanUpdate = ProductPriceCallService.updatePriceInMgo(productAllPriceBean,inaid);
				
				ret = getPriceByProdIdTradeIsolationCall.callAndGetReturnData(newBuyerId, productId);
				ret2 = getPriceByProdIdTradeIsolationCall.callAndGetReturnData(oldBuyerId, productId);
				
				if (PriceConfig.isCacheActivityProduct){
					ProductPriceCallService.checkPriceItem(ret, newProductPrice);
					ProductPriceCallService.checkPriceItem(ret2, oldProductPrice);
					
				}else{
					ProductPriceBean newProductPriceUpdate = ProductPriceCallService.getProductPriceBeanByUserLevel(productAllPriceBeanUpdate,true,false);
					ProductPriceCallService.checkPriceItem(ret, newProductPriceUpdate);
					
					ProductPriceBean oldProductPriceUpdate = ProductPriceCallService.getProductPriceBeanByUserLevel(productAllPriceBeanUpdate,false,false);
					ProductPriceCallService.checkPriceItem(ret2, oldProductPriceUpdate);
				}
				
				
				//修改时间戳，应该查询mongo库中数据，结果发生变化
				productTimeStampWapper.update(productId, MapUtil.hashMap("aut",new Date(),"cut",new Date())); 
				
				//新客修改后价格检查
				ProductPriceBean newProductPriceUpdate = ProductPriceCallService.getProductPriceBeanByUserLevel(productAllPriceBeanUpdate,true,false);
				ret = getPriceByProdIdTradeIsolationCall.callAndGetReturnData(newBuyerId, productId);
				ProductPriceCallService.checkPriceItem(ret, newProductPriceUpdate);
				
				//老客修改后价格检查
				ProductPriceBean oldProductPriceUpdate = ProductPriceCallService.getProductPriceBeanByUserLevel(productAllPriceBeanUpdate,false,false);
				ret2 = getPriceByProdIdTradeIsolationCall.callAndGetReturnData(oldBuyerId, productId);
				ProductPriceCallService.checkPriceItem(ret2, oldProductPriceUpdate);
			}
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetPriceByProdIdTradeIsolation_005() {
		Logger.start(true, "普通商品");
		try {

			String productId = ProductPriceCallService.getProductIdWithAllPrice();
			ProductAllPriceBean productAllPriceBean = ProductPriceCallService.getProductAllPrice(productId,0);
		
			//1 码头新客户 查询结果为普通商品价格
			ProductPriceBean newProductPrice = ProductPriceCallService.getProductPriceBeanByUserLevelAndIgnoreActivityPrice(productAllPriceBean,true);
			JSONObject ret = getPriceByProdIdTradeIsolationCall.callAndGetReturnData(newBuyerId, productId);
			ProductPriceCallService.checkPriceItem(ret, newProductPrice);
			
			
			//2码头老客户查询结果为普通商品价格
			//vip
			ProductPriceCallService.updateSellerBuyerToVipOrNot(ProductPriceCallService.sellerId, oldBuyerId, true);
			ProductPriceBean oldProductPrice = ProductPriceCallService.getProductPriceBeanByUserLevelAndIgnoreActivityPrice(productAllPriceBean,false);
			JSONObject ret2 = getPriceByProdIdTradeIsolationCall.callAndGetReturnData(oldBuyerId, productId);
			ProductPriceCallService.checkPriceItem(ret2, oldProductPrice);
			
			//no vip
			ProductPriceCallService.updateSellerBuyerToVipOrNot(ProductPriceCallService.sellerId, oldBuyerId, false);
			ProductPriceBean oldProductPriceNoVip = ProductPriceCallService.getProductOrigPriceBeanByUserLevel(productAllPriceBean, true);
			ret2 = getPriceByProdIdTradeIsolationCall.callAndGetReturnData(oldBuyerId, productId);
			ProductPriceCallService.checkPriceItem(ret2, oldProductPriceNoVip);
			ProductPriceCallService.updateSellerBuyerToVipOrNot(ProductPriceCallService.sellerId, oldBuyerId, true);
			
			
			if (PriceConfig.isCacheCheck){
				Logger.debug("缓存检查");
				//===========================================================================================================
				//修改mongo数据库价格，由于时间戳没有变化，应该查询缓存中数据，所以结果没有变
				ProductAllPriceBean productAllPriceBeanUpdate = ProductPriceCallService.updatePriceInMgo(productAllPriceBean);
				
				ret = getPriceByProdIdTradeIsolationCall.callAndGetReturnData(newBuyerId, productId);
				ProductPriceCallService.checkPriceItem(ret, newProductPrice);
				
				ret2 = getPriceByProdIdTradeIsolationCall.callAndGetReturnData(oldBuyerId, productId);
				ProductPriceCallService.checkPriceItem(ret2, oldProductPrice);
				
				//修改时间戳，应该查询mongo库中数据，结果发生变化
				productTimeStampWapper.update(productId, MapUtil.hashMap("cut",new Date())); 
				
				//新客修改后价格检查
				ProductPriceBean newProductPriceUpdate = ProductPriceCallService.getProductPriceBeanByUserLevelAndIgnoreActivityPrice(productAllPriceBeanUpdate,true);
				ret = getPriceByProdIdTradeIsolationCall.callAndGetReturnData(newBuyerId, productId);
				ProductPriceCallService.checkPriceItem(ret, newProductPriceUpdate);
				
				//老客修改后价格检查
				ProductPriceBean oldProductPriceUpdate = ProductPriceCallService.getProductPriceBeanByUserLevelAndIgnoreActivityPrice(productAllPriceBeanUpdate,false);
				ret2 = getPriceByProdIdTradeIsolationCall.callAndGetReturnData(oldBuyerId, productId);
				ProductPriceCallService.checkPriceItem(ret2, oldProductPriceUpdate);
			}
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetPriceByProdIdTradeIsolation_006() {
		Logger.start(true, "活动结束，应显示原价");
		try {
			ProductAllPriceBean productAllPriceBean = ProductPriceCallService.getProdPriceWithActivity_NoNewBuyerAndIsolation();
			String productId = productAllPriceBean.getProductId();
		
			//1 码头新客户 查询结果为活动价格
			ProductPriceBean newProductPrice = ProductPriceCallService.getProductPriceBeanByUserLevel(productAllPriceBean,true,false);
			JSONObject ret = getPriceByProdIdTradeIsolationCall.callAndGetReturnData(newBuyerId, productId);
			ProductPriceCallService.checkPriceItem(ret, newProductPrice);
			
			
			//2码头老客户查询结果为活动价格
			ProductPriceBean oldProductPrice = ProductPriceCallService.getProductPriceBeanByUserLevel(productAllPriceBean,false,false);
			JSONObject ret2 = getPriceByProdIdTradeIsolationCall.callAndGetReturnData(oldBuyerId, productId);
			ProductPriceCallService.checkPriceItem(ret2, oldProductPrice);
			
			if (PriceConfig.isCacheCheck){
				Logger.debug("缓存检查");
				//===========================================================================================================
				//修改mongo数据库活动商品结束时间，由于时间戳没有变化，应该查询缓存中数据，所以结果没有变
				int inaid = Integer.parseInt(activityProductsWapper.getByProdId(productId).get("inaid").toString());
				//activityProductsWapper.update(inaid, MapUtil.hashMap("end",YMTDateUtil.getBeforeOrNextDate(-1)));
				AdminCallService.closeProductInActivity(String.valueOf(inaid));
				
				//新客修改后价格检查
				ProductPriceBean newProductPriceUpdate = ProductPriceCallService.getProductPriceBeanByUserLevelAndIgnoreActivityPrice(productAllPriceBean,true);
				ret = getPriceByProdIdTradeIsolationCall.callAndGetReturnData(newBuyerId, productId);
				ProductPriceCallService.checkPriceItem(ret, newProductPriceUpdate);
				
				//老客修改后价格检查
				ProductPriceBean oldProductPriceUpdate = ProductPriceCallService.getProductPriceBeanByUserLevelAndIgnoreActivityPrice(productAllPriceBean,false);
				ret2 = getPriceByProdIdTradeIsolationCall.callAndGetReturnData(oldBuyerId, productId);
				ProductPriceCallService.checkPriceItem(ret2, oldProductPriceUpdate);
			}
			
			
		}catch (Exception e) {
			Logger.fail(e);
		}
		
	}
	
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetPriceByProdIdTradeIsolation_007() {
		Logger.start(true, "活动库存清零，应显示原价");
		try {
			ProductAllPriceBean productAllPriceBean = ProductPriceCallService.getProdPriceWithActivity_NoNewBuyerAndNoIsolation();
			String productId = productAllPriceBean.getProductId();
		
			//1 码头新客户 查询结果为活动价格
			ProductPriceBean newProductPrice = ProductPriceCallService.getProductPriceBeanByUserLevel(productAllPriceBean,true,false);
			JSONObject ret = getPriceByProdIdTradeIsolationCall.callAndGetReturnData(newBuyerId, productId);
			ProductPriceCallService.checkPriceItem(ret, newProductPrice);
			
			//2码头老客户查询结果为活动价格
			ProductPriceBean oldProductPrice = ProductPriceCallService.getProductPriceBeanByUserLevel(productAllPriceBean,false,false);
			JSONObject ret2 = getPriceByProdIdTradeIsolationCall.callAndGetReturnData(oldBuyerId, productId);
			ProductPriceCallService.checkPriceItem(ret2, oldProductPrice);
			
			if (PriceConfig.isCacheCheck){
				Logger.debug("缓存检查");
				//===========================================================================================================
				//修改mongo数据库活动库存，由于时间戳没有变化，应该查询缓存中数据，所以结果没有变
				int inaid = Integer.parseInt(activityProductsWapper.getByProdId(productId).get("inaid").toString());
				ProductPriceCallService.updateActivityStockTo0InMgo(productAllPriceBean, inaid);
				
			
				//新客修改后价格检查
				ProductPriceBean newProductPriceUpdate = ProductPriceCallService.getProductPriceBeanByUserLevelAndIgnoreActivityPrice(productAllPriceBean,true);
				ret = getPriceByProdIdTradeIsolationCall.callAndGetReturnData(newBuyerId, productId);
				ProductPriceCallService.checkPriceItem(ret, newProductPriceUpdate);
				
				//老客修改后价格检查
				ProductPriceBean oldProductPriceUpdate = ProductPriceCallService.getProductPriceBeanByUserLevelAndIgnoreActivityPrice(productAllPriceBean,false);
				ret2 = getPriceByProdIdTradeIsolationCall.callAndGetReturnData(oldBuyerId, productId);
				ProductPriceCallService.checkPriceItem(ret2, oldProductPriceUpdate);
			}
			
			
		}catch (Exception e) {
			Logger.fail(e);
		}
		
	}
	
	@Test
	@Ignore
	@Category(P1.class)
	@TestCase
	public void Tc_GetPriceByProdIdTradeIsolation_008() {
		Logger.start(true, "删除时间戳表后，查询");
		try{
			if (PriceConfig.isCacheCheck){
				ProductAllPriceBean productAllPriceBean = ProductPriceCallService.getProdPriceWithActivity_NoNewBuyerAndNoIsolation();
				String productId = productAllPriceBean.getProductId();
				//删除时间戳表记录
				productTimeStampWapper.delete(productId);
				
				//1 码头新客户 查询结果为活动价格
				ProductPriceBean newProductPrice = ProductPriceCallService.getProductPriceBeanByUserLevel(productAllPriceBean,true,false);
				JSONObject ret = getPriceByProdIdTradeIsolationCall.callAndGetReturnData(newBuyerId, productId);
				ProductPriceCallService.checkPriceItem(ret, newProductPrice);
				
				//2码头老客户查询结果为活动价格
				ProductPriceBean oldProductPrice = ProductPriceCallService.getProductPriceBeanByUserLevel(productAllPriceBean,false,false);
				JSONObject ret2 = getPriceByProdIdTradeIsolationCall.callAndGetReturnData(oldBuyerId, productId);
				ProductPriceCallService.checkPriceItem(ret2, oldProductPrice);
			
				//修改mongo数据库活动库存
				int inaid = Integer.parseInt(activityProductsWapper.getByProdId(productId).get("inaid").toString());
				ProductPriceCallService.updateActivityStockTo0InMgo(productAllPriceBean, inaid);
				
				YMTDateUtil.waitTime(5);
				//新客修改后价格检查
				ProductPriceBean newProductPriceUpdate = ProductPriceCallService.getProductPriceBeanByUserLevelAndIgnoreActivityPrice(productAllPriceBean,true);
				ret = getPriceByProdIdTradeIsolationCall.callAndGetReturnData(newBuyerId, productId);
				ProductPriceCallService.checkPriceItem(ret, newProductPriceUpdate);
				
				//老客修改后价格检查
				ProductPriceCallService.updateSellerBuyerToVipOrNot(ProductPriceCallService.sellerId, oldBuyerId, true);
				ProductPriceBean oldProductPriceUpdate = ProductPriceCallService.getProductPriceBeanByUserLevelAndIgnoreActivityPrice(productAllPriceBean,false);
				ret2 = getPriceByProdIdTradeIsolationCall.callAndGetReturnData(oldBuyerId, productId);
				ProductPriceCallService.checkPriceItem(ret2, oldProductPriceUpdate);
				
				
				ProductPriceCallService.updateSellerBuyerToVipOrNot(ProductPriceCallService.sellerId, oldBuyerId, false);
				ProductPriceBean oldProductPriceNoVip = ProductPriceCallService.getProductOrigPriceBeanByUserLevel(productAllPriceBean, true);
				ret2 = getPriceByProdIdTradeIsolationCall.callAndGetReturnData(oldBuyerId, productId);
				ProductPriceCallService.checkPriceItem(ret2, oldProductPriceNoVip);
				ProductPriceCallService.updateSellerBuyerToVipOrNot(ProductPriceCallService.sellerId, oldBuyerId, true);
				
			}
			
			
			
			
		}catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetPriceByProdIdTradeIsolation_009() {
		Logger.start(true, "非交易隔离,会员活动");
		try {
			ProductAllPriceBean productAllPriceBean = ProductPriceCallService.getProdPriceWithActivity_NoNewBuyerAndNoIsolation_Member();
			String productId = productAllPriceBean.getProductId();
			
			
			int prodInActivityId = Integer.parseInt(activityProductsWapper.getByProdId(productId).get("inaid").toString());
			
			
			//新客 普通价
			ProductPriceBean priceIgnoreActivity_NewCust = ProductPriceCallService.getProductPriceBeanByUserLevel(productAllPriceBean,true,true);
			//新客 会员价
			ProductPriceBean priceIncludeActivity_NewCust = ProductPriceCallService.getProductPriceBeanByUserLevel(productAllPriceBean,true,false);
			//老客 普通价
			ProductPriceBean priceIgnoreActivity_OleCust = ProductPriceCallService.getProductPriceBeanByUserLevel(productAllPriceBean,false,true);
			//老客 会员价
			ProductPriceBean priceIncludeActivity_OleCust = ProductPriceCallService.getProductPriceBeanByUserLevel(productAllPriceBean,false,false);
			
			
			//会员政策1， 会员等级3以上才能享受活动价
			
			ProductPriceCallService.updateActivityMemberPolicy(prodInActivityId, 1, "3,4,5,6");
			//0级会员 新客 普通价
			JSONObject ret1 = getPriceByProdIdTradeIsolationCall.callAndGetReturnData(newBuyerId, productId);
			ProductPriceCallService.checkPriceItem(ret1, priceIgnoreActivity_NewCust);
			
			//6级会员  老客 会员活动价
			JSONObject ret2 = getPriceByProdIdTradeIsolationCall.callAndGetReturnData(oldBuyerId, productId);
			ProductPriceCallService.checkPriceItem(ret2, priceIncludeActivity_OleCust);
			
			
			//会员政策2，会员注册时间在2017-01-02 到 2017-03-23 才能享受活动价
			ProductPriceCallService.updateActivityMemberPolicy(prodInActivityId, 2, "2015-01-02 00:00:00,2016-03-23 23:59:59");
			
			//新客 注册时间2015-05-26 14:20:04 会员活动价
			JSONObject ret3 = getPriceByProdIdTradeIsolationCall.callAndGetReturnData(newBuyerId, productId);
			ProductPriceCallService.checkPriceItem(ret3, priceIncludeActivity_NewCust);
			
			//老客 注册时间2016-04-22 10:19:05 普通价格
			JSONObject ret4 = getPriceByProdIdTradeIsolationCall.callAndGetReturnData(oldBuyerId, productId);
			ProductPriceCallService.checkPriceItem(ret4, priceIgnoreActivity_OleCust);
			
			
			//会员政策3， 会员标签满足才能享受活动价  标签值 3 
			ProductPriceCallService.updateActivityMemberPolicy(prodInActivityId,3, "3");
			
			//新客  标签3  会员活动价
			JSONObject ret5 = getPriceByProdIdTradeIsolationCall.callAndGetReturnData(newBuyerId, productId);
			ProductPriceCallService.checkPriceItem(ret5, priceIncludeActivity_NewCust);
			
			//老客 没标签 普通价格
			JSONObject ret6 = getPriceByProdIdTradeIsolationCall.callAndGetReturnData(oldBuyerId, productId);
			ProductPriceCallService.checkPriceItem(ret6, priceIgnoreActivity_OleCust);
			
			//会员政策3， 会员标签满足才能享受活动价  标签值 4
			ProductPriceCallService.updateActivityMemberPolicy(prodInActivityId,3, "4");
			
			//新客  标签3  普通价
			JSONObject ret7 = getPriceByProdIdTradeIsolationCall.callAndGetReturnData(newBuyerId, productId);
			ProductPriceCallService.checkPriceItem(ret7, priceIgnoreActivity_NewCust);
			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetPriceByProdIdTradeIsolation_010() {
		Logger.start(true, "交易隔离,会员活动");
		try {
			ProductAllPriceBean productAllPriceBean = ProductPriceCallService.getProdPriceWithActivity_NoNewBuyerAndIsolation_Member();
			String productId = productAllPriceBean.getProductId();
			
			
			int prodInActivityId = Integer.parseInt(activityProductsWapper.getByProdId(productId).get("inaid").toString());
			
			
			//新客 普通价
			ProductPriceBean priceIgnoreActivity_NewCust = ProductPriceCallService.getProductPriceBeanByUserLevel(productAllPriceBean,true,true);
			//新客 会员价
			ProductPriceBean priceIncludeActivity_NewCust = ProductPriceCallService.getProductPriceBeanByUserLevel(productAllPriceBean,true,false);
			//老客 普通价
			ProductPriceBean priceIgnoreActivity_OleCust = ProductPriceCallService.getProductPriceBeanByUserLevel(productAllPriceBean,false,true);
			//老客 会员价
			ProductPriceBean priceIncludeActivity_OleCust = ProductPriceCallService.getProductPriceBeanByUserLevel(productAllPriceBean,false,false);
			//原价
			ProductPriceBean priceIgnoreActivity_OleOrig = ProductPriceCallService.getProductOrigPriceBeanByUserLevel(productAllPriceBean,true);
			
			//会员政策1， 会员等级3以上才能享受活动价
			
			ProductPriceCallService.updateActivityMemberPolicy(prodInActivityId, 1, "3,4,5,6");
			//0级会员 新客 普通价
			JSONObject ret1 = getPriceByProdIdTradeIsolationCall.callAndGetReturnData(newBuyerId, productId);
			ProductPriceCallService.checkPriceItem(ret1, priceIgnoreActivity_NewCust);
			
			//6级会员  老客 会员活动价
			JSONObject ret2 = getPriceByProdIdTradeIsolationCall.callAndGetReturnData(oldBuyerId, productId);
			ProductPriceCallService.checkPriceItem(ret2, priceIncludeActivity_OleCust);
			
			
			//会员政策2，会员注册时间在2017-01-02 到 2017-03-23 才能享受活动价
			ProductPriceCallService.updateActivityMemberPolicy(prodInActivityId, 2, "2015-01-02 00:00:00,2016-03-23 23:59:59");
			
			//新客 注册时间2015-05-26 14:20:04 会员活动价
			JSONObject ret3 = getPriceByProdIdTradeIsolationCall.callAndGetReturnData(newBuyerId, productId);
			ProductPriceCallService.checkPriceItem(ret3, priceIncludeActivity_NewCust);
			
			//老客 注册时间2016-04-22 10:19:05 普通价格
			JSONObject ret4 = getPriceByProdIdTradeIsolationCall.callAndGetReturnData(oldBuyerId, productId);
			ProductPriceCallService.checkPriceItem(ret4, priceIgnoreActivity_OleCust);
			
			
			//会员政策3， 会员标签满足才能享受活动价  标签值 3 
			ProductPriceCallService.updateActivityMemberPolicy(prodInActivityId,3, "3");
			
			//新客  标签3  会员活动价
			JSONObject ret5 = getPriceByProdIdTradeIsolationCall.callAndGetReturnData(newBuyerId, productId);
			ProductPriceCallService.checkPriceItem(ret5, priceIncludeActivity_NewCust);
			
			//老客 没标签 普通价格
			//vip
			ProductPriceCallService.updateSellerBuyerToVipOrNot(ProductPriceCallService.sellerId, oldBuyerId, true);
			JSONObject ret6 = getPriceByProdIdTradeIsolationCall.callAndGetReturnData(oldBuyerId, productId);
			ProductPriceCallService.checkPriceItem(ret6, priceIgnoreActivity_OleCust);
			
			
			//no vip
			ProductPriceCallService.updateSellerBuyerToVipOrNot(ProductPriceCallService.sellerId, oldBuyerId, false);
			ret6 = getPriceByProdIdTradeIsolationCall.callAndGetReturnData(oldBuyerId, productId);
			ProductPriceCallService.checkPriceItem(ret6, priceIgnoreActivity_OleOrig);
			ProductPriceCallService.updateSellerBuyerToVipOrNot(ProductPriceCallService.sellerId, oldBuyerId, true);
			
			
			//会员政策3， 会员标签满足才能享受活动价  标签值 4
			ProductPriceCallService.updateActivityMemberPolicy(prodInActivityId,3, "4");
			
			//新客  标签3  普通价
			JSONObject ret7 = getPriceByProdIdTradeIsolationCall.callAndGetReturnData(newBuyerId, productId);
			ProductPriceCallService.checkPriceItem(ret7, priceIgnoreActivity_NewCust);
			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetPriceByProdIdTradeIsolation_012() {
		Logger.start(true, "测试缓存ExtraDeliveryType,ExtraDeliveryFee");
		try {
			String productId = ProductPriceCallService.getProductIdWithAllPrice();
			ProductAllPriceBean productAllPriceBean = ProductPriceCallService.getProductAllPrice(productId,0);
		
			//1 码头新客户 查询结果为普通商品价格
			ProductPriceBean newProductPrice = ProductPriceCallService.getProductPriceBeanByUserLevelAndIgnoreActivityPrice(productAllPriceBean,true);
			JSONObject ret = getPriceByProdIdTradeIsolationCall.callAndGetReturnData(newBuyerId, productId);
			ProductPriceCallService.checkPriceItem(ret, newProductPrice);
			
			
			//修改ExtraDeliveryType,ExtraDeliveryFee ， 不修改时间戳
			new ProductsWapper().updateAll(MapUtil.hashMap("spid",productId), MapUtil.hashMap("mdeliv",2,"mflight",3.1));
			JSONObject ret1 = getPriceByProdIdTradeIsolationCall.callAndGetReturnData(newBuyerId, productId);
			ProductPriceCallService.checkPriceItem(ret1, newProductPrice);
			
			
			//修改时间戳
			new ProductTimeStampWapper().update(productId, MapUtil.hashMap("sut",new Date()));
			ProductPriceBean newProductPrice2 = ProductPriceCallService.getProductPriceBeanByUserLevelAndIgnoreActivityPrice(productAllPriceBean,true);
			JSONObject ret2 = getPriceByProdIdTradeIsolationCall.callAndGetReturnData(newBuyerId, productId);
			ProductPriceCallService.checkPriceItem(ret2, newProductPrice2);
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetPriceByProdIdTradeIsolation_999() {
		Logger.start(true, "非法数据测试");
		try {
			//不存在 商品id
			JSONObject ret = getPriceByProdIdTradeIsolationCall.callAndGetReturnData(newBuyerId, "111212312");
			ProductPriceCallService.checkInvalidResponse(ret);
			
			//buyerid<0
			String productId = ProductPriceCallService.getProductIdWithAllPrice();
			JSONObject ret1 = getPriceByProdIdTradeIsolationCall.callAndGetReturnData(-1, productId);
			ProductPriceCallService.checkInvalidResponse(ret1);
			
			//没有productid参数
			JSONObject ret2 = getPriceByProdIdTradeIsolationCall.callAndGetReturnData();
			ProductPriceCallService.checkInvalidResponse(ret2);
			
		}catch (Exception e) {
			Logger.fail(e);
		}
	
	}
	
	

}
